<?php
namespace app\common\dao\apps;

use app\common\dao\BaseDao;
use app\common\model\apps\AppsAppsModel;

/**
 * AppsAccess数据访问层
 */
class AppsAppsDao extends BaseDao
{
    /**
     * 获取模型类名
     * @return string
     */
    protected function getModel(): string 
    {
        return AppsAppsModel::class;
    }

    /**
     * 搜索构造器
     * @param array $where 查询条件
     * @return \think\db\Query
     */
    public function search(array $where = [])
    {
        $query = AppsAppsModel::getDB()
            ->when(isset($where['id']) && !empty($where['id']), function ($query) use($where) {
                if (is_array($where['id'])) {
                    $query->whereIn('id', $where['id']);
                } else {
                    $query->where('id', $where['id']);
                }
            })
            ->when(isset($where['appkey']) && $where['appkey'] !== '', function ($query) use ($where) {
                $query->whereLike('appkey', '%' . trim($where['appkey']) . '%');
            })->when(isset($where['appkey_key']) && $where['appkey_key'] !== '', function ($query) use ($where) {
                $query->where('appkey', $where['appkey_key']);
            })->when(isset($where['fingerprint']) && $where['fingerprint'] !== '', function ($query) use ($where) {
                $query->whereLike('fingerprint', '%' . trim($where['fingerprint']) . '%');
            })->when(isset($where['fingerprint_key']) && $where['fingerprint_key'] !== '', function ($query) use ($where) {
                $query->where('fingerprint', $where['fingerprint_key']);
            })->when(isset($where['version']) && $where['version'] !== '', function ($query) use($where) {
                $query->where('version', $where['version']);
            })->when(isset($where['is_del']) && $where['is_del'] !== '', function ($query) use($where) {
                $query->where('is_del', $where['is_del']);
            })->when(isset($where['status']) && $where['status'] !== '', function ($query) use($where) {
                $query->where('status', $where['status']);
            });

        return $query;
    }
}
